﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DoAn_BumTruong_DesignPattern
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["LoginReferrer"] = Request.QueryString["ReturnUrl"] ?? (Page.Request.UrlReferrer != null ? Page.Request.UrlReferrer.ToString() : "~/");
            }
            if (User.Identity.IsAuthenticated)
            {
                FormsAuthentication.SignOut();
                Response.Redirect("~/");
            }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            LoginUser.LoggedIn += LoginUser_LoggedIn;
        }

        void LoginUser_LoggedIn(object sender, EventArgs e)
        {
            if (Session["LoginReferrer"] != null)
            {
                Response.Redirect(Session["LoginReferrer"].ToString());
            }
            //throw new NotImplementedException();
        }
    }
}